<template>
	<view class="">
		<view class="radius margin-top overflow-hidden">
			<view class="padding-sm bg-main text-white flex justify-between align-center">
				<text>共计【{{mdtotal}}】家门店</text>
				<text @tap="toMdSearch">显示更多<text class="cuIcon-right"></text></text>
			</view>
			<view v-if="mds.length > 0" class="flex justify-between  align-start">
				<view class="inline-block w-50 padding-xs">
					<view @tap="toMdDetail(md.mdid)" class="margin-bottom-xs" v-if="index % 2 == 0" v-for="(md,index) in mds" :key="index">
						<view class="shadow radius bg-white overflow-hidden">
							<view class="relative w-100 radius overflow-hidden">
								<view class="img-cover relative">
								</view>
								<view class="absolute top0 w-100 h-100">
									<image class="w-100 h-100" mode="aspectFill" :src="md.cover"></image>
								</view>
							</view>
							<view class="bg-white">
								<view class="padding-xs">{{md.mdmc}}</view>
								<view class="padding-xs">{{locamap[md.pcode].criname}}{{locamap[md.scode].criname}}{{locamap[md.qcode].criname}}
									{{md.address}}</view>
								<view class="flex justify-between align-center padding-xs">
									<!-- <text>{{md.mj}}㎡</text> -->
									<text>{{md.roomsize}}个房间</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="inline-block w-50 padding-xs">
					<view @tap="toMdDetail(md.mdid)" class="margin-bottom-xs" v-if="index % 2 == 1" v-for="(md,index) in mds" :key="index">
						<view class="shadow radius bg-white overflow-hidden">
							<view class="relative w-100 radius overflow-hidden">
								<view class="img-cover relative">
								</view>
								<view class="absolute top0 w-100 h-100">
									<image class="w-100 h-100" mode="aspectFill" :src="md.cover"></image>
								</view>
							</view>
							<view class="bg-white">
								<view class="padding-xs">{{md.mdmc}}</view>
								<view class="padding-xs">{{locamap[md.pcode].criname}}{{locamap[md.scode].criname}}{{locamap[md.qcode].criname}}
									{{md.address}}</view>
								<view class="flex justify-between align-center padding-xs">
									<!-- <text>{{md.mj}}㎡</text> -->
									<text>{{md.roomsize}}个房间</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="padding text-gray text-center">暂无记录</view>
		</view>
		
		
		<view class="radius margin-top  overflow-hidden">
			<view class="padding-sm bg-main text-white flex justify-between align-center">
				<text>共计【{{fjtotal}}】个房间</text>
				<text @tap="toFjSearch">显示更多<text class="cuIcon-right"></text></text>
			</view>
			<view v-if="fjs.length > 0" class="">
				<view class="padding-xs " v-for="(fj,index) in fjs" :key="index">
					<view class="bg-white shadow radius padding-xxs flex justify-between">
						<view class="w-25">
							<view class="relative w-100 radius overflow-hidden">
								<view class="img-cover relative">
								</view>
								<view class="absolute top0 w-100 h-100">
									<image class="w-100 h-100" mode="aspectFill" :src="fj.cover"></image>
								</view>
							</view>
							<view>
								
							</view>
						</view>
						<view class="w-75">
							<view class="padding-xs">
								<text>{{fj.fjmc}}</text>
							</view>
							<view class="padding-xs">
								<text>{{fj.mdmc}}</text>
							</view>
							<view class="padding-xs flex justify-between align-center">
								<text>{{fj.mj}}㎡</text>
								<uni-rate size="14"  :value="fj.rate"></uni-rate>
							</view>
							<view class="padding-xs flex justify-between align-center">
								<view>{{tp[fj.tp]}}</view>
								<view>{{func[fj.func]}}</view>
							</view>
							<view class="padding-xs flex justify-between align-center">
								<view>{{fj.yyitems}}次预约</view>
								<view><text @tap="toFjDetail(fj.fjid)" class="cu-tag bg-main radius">预约</text></view>
							</view>
							
						</view>
						
					</view>
				</view>
			</view>
			<view v-else class="padding text-gray text-center">暂无记录</view>
		</view>	
	</view>
</template>

<script>
	export default {
		computed: {
			currentPosition: function() {
				if (this.store.state.position) {
					return this.store.state.position;
				}
				return undefined;
			}
		},
		data: function() {
			return {
				CustomBar: this.CustomBar,
				StatusBar: this.StatusBar,
				tp: {},
				func: {},
				locamap: {},
				fjs: [],
				mds: [],
				mdtotal: 0,
				fjtotal: 0,
			}
		},
		created: function() {
			this.constant.get("ROOMFUNC").then(data => {
				this.func = data.ROOMFUNC;
			});
			this.constant.get("ROOMTP").then(data => {
				this.tp = data.ROOMTP;
			});
			this.locamap = this.location.localmap.cmap;
			this.loadMds();
			this.loadFjs();
		},
		methods: {
			loadMds: function() {
				let param = {
					current: 1,
					size: 4,
					flg: true
				};
				if (this.currentPosition) {
					param.jd = this.currentPosition.jd;
					param.wd = this.currentPosition.wd;
				}
				this.api("/md/page/get").send(param).then(data => {
					this.mdtotal = data.mds.total;
					for (let index in data.mds.records) {
						let record = data.mds.records[index];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.mds.push(record);
					}
				});
			
			},
			loadFjs: function() {
				let param = {};
				param.current = 1;
				param.size = 4;
				param.flg = true;

				this.api("/fj/page/get").send(param).then(data => {
					this.fjtotal = data.fjs.total;
					for (let index in data.fjs.records) {
						let record = data.fjs.records[index];
						record.sheng = this.locamap[record.pcode].criname;
						record.shi = this.locamap[record.scode].criname;
						record.qu = this.locamap[record.qcode].criname;
						record.tpname = this.tp[record.tp];
						record.funcname = this.func[record.func];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.fjs.push(record);
					}
				});
				
			},
			toMdSearch: function(id) {
				uni.navigateTo({
					url: `/pages/cmd/md/search` 
				})
			},
			toMdDetail: function(id) {
				uni.navigateTo({
					url: `/pages/cmd/md/detail?mdid=${id}` 
				})
			},
			toFjSearch: function(id) {
				uni.navigateTo({
					url: `/pages/cmd/fj/search` 
				})
			},
			toFjDetail: function(id) {
				uni.navigateTo({
					url: `/pages/cmd/fj/detail?fjid=${id}` 
				})
			}
		}
	}
</script>

<style>
</style>